package com.blockmeta.bbs.businesslibrary.widget.textview;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;

import com.blockmeta.bbs.baselibrary.R;
import com.blockmeta.bbs.baselibrary.base.app.BaseApp;

import skin.support.widget.SkinCompatTextView;


public class CustomFontText extends SkinCompatTextView
{
	public enum FONT_TYPE
	{
		DIN_ALTERNATE_BOLD(0, "fonts/DIN-Bold.ttf"),
		DIN_ALTERNATE(1, "fonts/DIN-Light.ttf"),
		ROBOTO_REGULAR(2, "fonts/Roboto Regular.ttf"), 
		NORMAL(3, ""), 
		HELVETICA_45_LIGHT(4, "fonts/helvetica_45_light.ttf"), 
		HELVETICA(5, "fonts/Helvetica.ttf"), 
		HELVETICALT(6, "fonts/HelveticaLt.ttf");

		private int m_value;
		private String m_strName;

		FONT_TYPE(int value, String pName)
		{
			m_value = value;
			m_strName = pName;
		}

		public int getValue()
		{
			return m_value;
		}

		@Override
		public String toString()
		{
			return m_strName;
		}

		public static FONT_TYPE getFontType(int format)
		{
			switch (format)
			{
			case 1:
				return DIN_ALTERNATE;
			case 2:
				return ROBOTO_REGULAR;
			case 3:
				return NORMAL;
			case 4:
				return HELVETICA_45_LIGHT;
			case 5:
				return HELVETICA;
			case 6:
				return HELVETICALT;
			default:
				return DIN_ALTERNATE_BOLD;
			}
		}
	}
	
	public CustomFontText(Context context)
	{
		super(context);

		FONT_TYPE fontype = FONT_TYPE.getFontType(FONT_TYPE.DIN_ALTERNATE_BOLD.getValue());

		if (BaseApp.isUseDefualtFont())
			fontype = FONT_TYPE.getFontType(FONT_TYPE.NORMAL.getValue());

		setFontType(fontype);
	}

	public CustomFontText(Context context, AttributeSet attrs)
	{
		super(context, attrs);
		init(context, attrs);
	}

	public CustomFontText(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);
		init(context, attrs);
	}
	
	private void init(Context context, AttributeSet attrs)
	{
		TypedArray tTypeeArr = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomFontText, 0, 0);

		if (tTypeeArr != null)
		{
			FONT_TYPE fontype = FONT_TYPE.getFontType(tTypeeArr.getInt(R.styleable.CustomFontText_fontType, FONT_TYPE.DIN_ALTERNATE_BOLD.getValue()));

			if (BaseApp.isUseDefualtFont())
				fontype = FONT_TYPE.getFontType(tTypeeArr.getInt(R.styleable.CustomFontText_fontType, FONT_TYPE.NORMAL.getValue()));

			setFontType(fontype);

			tTypeeArr.recycle();
		}
	}

	private void initialize()
	{
		
	}
	
	@Override
	public final void setTypeface(Typeface tf)
	{
	}
	
	@Override
	public final void setTypeface(Typeface tf, int style)
	{
	}


	public void setFontType(FONT_TYPE pType)
	{
		switch (pType)
		{
		case DIN_ALTERNATE:
		case ROBOTO_REGULAR:
		case DIN_ALTERNATE_BOLD:
		case HELVETICA:
		case HELVETICA_45_LIGHT:
		case HELVETICALT:
		{
			AssetManager assetManager=BaseApp.getApp().getAssets();
			Typeface tNewFont = Typeface.createFromAsset(assetManager,pType.toString());
			super.setTypeface(tNewFont);
		}
			break;
		default:
			super.setTypeface(Typeface.DEFAULT);
			break;
		}
	}
}
